package com.shopReduce.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.shopReduce.bean.ReduceProgramme;
import com.shopReduce.sql.ReduceProgrammeBuilder;

import shopBean.common.Enum.StatusAll;

@Mapper
public interface ReduceProgrammeMapper {
	@SelectProvider(type=ReduceProgrammeBuilder.class,method="list")
	public List<ReduceProgramme> list(ReduceProgramme search);
	@Insert("insert into sys_reduce_programme set id=#{id},name=#{name},parm1=#{parm1},parm2=#{parm2},createDate=#{createDate},type=#{type},expireDate=#{expireDate},status=#{status},beginDate=#{beginDate}")
	public int insert(ReduceProgramme reduceProgramme);
	@Select("select * from sys_reduce_programme where name=#{name}")
	public ReduceProgramme getByName(String name);
	@SelectProvider(type=ReduceProgrammeBuilder.class,method="listCount")
	public long listCount(ReduceProgramme search);
	@Delete("update  sys_reduce_programme set status=#{status} where id=#{id}")
	public int updateStatus(String id,StatusAll status);
	@Select("select * from sys_reduce_programme where id=#{id}")
	public ReduceProgramme get(String id);
	
	@Select("select sys_reduce_programme.id,sys_reduce_programme.name,sys_reduce_programme.parm1,sys_reduce_programme.parm2,sys_reduce_programme.createDate,sys_shop_reduce.expireDate from sys_reduce_programme inner join sys_shop_reduce on(sys_shop_reduce.reduceId=sys_reduce_programme.id) where sys_shop_reduce.shopId=#{shopId} and sys_reduce_programme.status=#{status}")
	public List<ReduceProgramme> getByShopIdAndStatus(@Param("shopId")String shopId,@Param("status")StatusAll status);
	
	@Select("select sys_reduce_programme.id,sys_reduce_programme.name,sys_reduce_programme.parm1,sys_reduce_programme.parm2,sys_reduce_programme.createDate,sys_shop_reduce.expireDate from sys_reduce_programme inner join sys_shop_reduce on(sys_shop_reduce.reduceId=sys_reduce_programme.id) where sys_shop_reduce.shopId=#{shopId} and sys_reduce_programme.status=#{status} order by sys_reduce_programme.sort desc limit 0,1")
	public ReduceProgramme getFirstByShopIdAndStatus(@Param("shopId")String shopId,@Param("status")StatusAll status);
	
}
